/**
 * @description 作品 数据操作
 */
const { GoodsModel, GoodsCategoryModel } = require("../models/GoodsModel");
/**
 * 创建产品
 */
async function createGoodsService(data = {}) {
  const goods = await GoodsModel.create(data);
  return goods;
}
/**
 * @description 创建产品列表
 * @returns
 */
async function createGoodsCategoryService(data = {}) {
  const goods = await GoodsCategoryModel.create(data);
  return goods;
}
/**
 * 查询所有产品
 */
async function findGoodsListService() {
  const goods = await GoodsModel.find();
  return goods;
}

async function findGoodsByCategoryIdService(categoryId) {
  console.log("categoryId", categoryId);
  const goods = await GoodsModel.find().where({
    cId: categoryId,
  });
  return goods;
}
/**
 * 查询所有产品列表
 */
async function findGoodsCategoryListService() {
  const goodsCategoryList = await GoodsCategoryModel.find().sort({
    orderIndex: -1,
  });
  return goodsCategoryList;
}

/**
 * 查询展示列表详细信息
 * */
async function findGoodsDetailIdService(detailId) {
  console.log("detailId", detailId);
  const goods = await GoodsModel.find().where({
    _id: detailId,
  });
  return goods;
}

module.exports = {
  findGoodsListService,
  findGoodsCategoryListService,
  createGoodsService,
  createGoodsCategoryService,
  findGoodsByCategoryIdService,
  findGoodsDetailIdService,
};
